
export default {
  components: {
    Config: () => import('./Config.vue'),
    ConfigStep: () => import('./configStep.vue')
  },
  data() {
    return {
      currentStep: 0,
      scanType: '',
      scanOrders: [],
      configVisible: false,
      scanResults: []
    }
  },
  created() {
    if (!this.scanType) {
      this.$message.error('scanType不能为空')
    }
  },
  methods: {
    // 设置扫码顺序
    setScanOrders(items) {
      console.log(items)
      this.scanOrders = items
    },
    // 设置配置项弹窗显示/隐藏
    setConfigVisible(visible = true) {
      this.configVisible = !!visible
    },
    // 追加扫码结果
    addScanResults(event) {
      let val = typeof event === 'string' ? event : (event && event.target ? event.target.value : '')
      console.log(event)
      val = val.trim()
      if (!val) {
        this.$message.warning('无效条码')
        return
      }
      if (this.scanResults.length >= this.scanOrders.length) {
        this.resetScanResults()
      }
      this.scanResults.push(val)
      this.currentStep++
    },
    // 重置扫码内容
    resetScanResults() {
      this.currentStep = 0
      this.scanResults = []
      // 可添加自定义重置操作
      if (this.customResetScanResults) {
        this.customResetScanResults()
      }
    },
    onScanConfigSuccess() {
      this.$refs.configStep && this.$refs.configStep.getData()
    }
  },
}